# (C) Datadog, Inc. 2020-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

METRICS_MAP = {
    'action_cable_active_connections': 'action_cable.active_connections',
    'auto_devops_pipelines_completed_total': 'auto_devops_pipelines_completed_total',
    'db_load_balancing_hosts': 'db_load_balancing_hosts',
    'db_partitions_missing': 'db_partitions_missing',
    'db_partitions_present': 'db_partitions_present',
    'failed_login_captcha_total': 'failed_login_captcha_total',
    'geo_attachments': 'geo.attachments',
    'geo_attachments_failed': 'geo.attachments_failed',
    'geo_attachments_synced': 'geo.attachments_synced',
    'geo_attachments_synced_missing_on_primary': 'geo.attachments_synced_missing_on_primary',
    'geo_cursor_last_event_id': 'geo.cursor_last_event_id',
    'geo_cursor_last_event_timestamp': 'geo.cursor_last_event_timestamp',
    'geo_db_replication_lag_seconds': 'geo.db_replication_lag_seconds',
    'geo_job_artifacts_synced_missing_on_primary': 'geo.job_artifacts_synced_missing_on_primary',
    'geo_group_wiki_repositories': 'geo.group.wiki.repositories',
    'geo_group_wiki_repositories_checksum_total': 'geo.group.wiki.repositories_checksum_total',
    'geo_group_wiki_repositories_checksummed': 'geo.group.wiki.repositories_checksummed',
    'geo_group_wiki_repositories_checksum_failed': 'geo.group.wiki.repositories_checksum_failed',
    'geo_group_wiki_repositories_synced': 'geo.group.wiki.repositories_synced',
    'geo_group_wiki_repositories_failed': 'geo.group.wiki.repositories_failed',
    'geo_group_wiki_repositories_registry': 'geo.group.wiki.repositories_registry',
    'geo_group_wiki_repositories_verification_total': 'geo.group.wiki.repositories_verification_total',
    'geo_group_wiki_repositories_verified': 'geo.group.wiki.repositories_verified',
    'geo_group_wiki_repositories_verification_failed': 'geo.group.wiki.repositories_verification_failed',
    'geo_last_event_id': 'geo.last_event_id',
    'geo_last_event_timestamp': 'geo.last_event_timestamp',
    'geo_last_successful_status_check_timestamp': 'geo.last_successful_status_check_timestamp',
    'geo_lfs_objects': 'geo.lfs_objects',
    'geo_lfs_objects_failed': 'geo.lfs_objects_failed',
    'geo_lfs_objects_synced': 'geo.lfs_objects_synced',
    'geo_lfs_objects_synced_missing_on_primary': 'geo.lfs_objects_synced_missing_on_primary',
    'geo_merge_request_diffs': 'geo.merge_request_diffs',
    'geo_merge_request_diffs_checksum_failed': 'geo.merge_request_diffs_checksum_failed',
    'geo_merge_request_diffs_checksummed': 'geo.merge_request_diffs_checksummed',
    'geo_merge_request_diffs_failed': 'geo.merge_request_diffs_failed',
    'geo_merge_request_diffs_registry': 'geo.merge_request_diffs_registry',
    'geo_merge_request_diffs_synced': 'geo.merge_request_diffs_synced',
    'geo_package_files': 'geo.package_files',
    'geo_package_files_checksum_failed': 'geo.package_files_checksum_failed',
    'geo_package_files_checksummed': 'geo.package_files_checksummed',
    'geo_package_files_failed': 'geo.package_files_failed',
    'geo_package_files_registry': 'geo.package_files_registry',
    'geo_package_files_synced': 'geo.package_files_synced',
    'geo_project_repositories': 'geo.project.repositories',
    'geo_project_repositories_checksum_total': 'geo.project.repositories_checksum_total',
    'geo_project_repositories_checksummed': 'geo.project.repositories_checksummed',
    'geo_project_repositories_checksum_failed': 'geo.project.repositories_checksum_failed',
    'geo_project_repositories_failed': 'geo.project.repositories_failed',
    'geo_project_repositories_registry': 'geo.project.repositories_registry',
    'geo_project_repositories_synced': 'geo.project.repositories_synced',
    'geo_project_repositories_verification_total': 'geo.project.repositories_verification_total',
    'geo_project_repositories_verified': 'geo.project.repositories_verified',
    'geo_project_repositories_verification_failed': 'geo.project.repositories_verification_failed',
    'geo_project_wiki_repositories': 'geo.project.wiki.repositories',
    'geo_project_wiki_repositories_checksum_total': 'geo.project.wiki.repositories_checksum_total',
    'geo_project_wiki_repositories_checksummed': 'geo.project.wiki.repositories_checksummed',
    'geo_project_wiki_repositories_checksum_failed': 'geo.project.wiki.repositories_checksum_failed',
    'geo_project_wiki_repositories_synced': 'geo.project.wiki.repositories_synced',
    'geo_project_wiki_repositories_failed': 'geo.project.wiki.repositories_failed',
    'geo_project_wiki_repositories_registry': 'geo.project.wiki.repositories_registry',
    'geo_project_wiki_repositories_verification_total': 'geo.project.wiki.repositories_verification_total',
    'geo_project_wiki_repositories_verified': 'geo.project.wiki.repositories_verified',
    'geo_project_wiki_repositories_verification_failed': 'geo.project.wiki.repositories_verification_failed',
    'geo_repositories': 'geo.repositories',
    'geo_repositories_checked': 'geo.repositories_checked_count',
    'geo_repositories_checked_count': 'geo.repositories_checked_count',
    'geo_repositories_checked_failed': 'geo.repositories_checked_failed_count',
    'geo_repositories_checked_failed_count': 'geo.repositories_checked_failed_count',
    'geo_repositories_checksum_failed': 'geo.repositories_checksum_failed_count',
    'geo_repositories_checksum_failed_count': 'geo.repositories_checksum_failed_count',
    'geo_repositories_checksum_mismatch': 'geo.repositories_checksum_mismatch_count',
    'geo_repositories_checksum_mismatch_count': 'geo.repositories_checksum_mismatch_count',
    'geo_repositories_checksummed': 'geo.repositories_checksummed',
    'geo_repositories_checksummed_count': 'geo.repositories_checksummed_count',
    'geo_repositories_failed': 'geo.repositories_failed',
    'geo_repositories_retrying_verification': 'geo.repositories_retrying_verification_count',
    'geo_repositories_retrying_verification_count': 'geo.repositories_retrying_verification_count',
    'geo_repositories_synced': 'geo.repositories_synced',
    'geo_repositories_verification_failed': 'geo.repositories_verification_failed_count',
    'geo_repositories_verification_failed_count': 'geo.repositories_verification_failed_count',
    'geo_repositories_verified': 'geo.repositories_verified_count',
    'geo_repositories_verified_count': 'geo.repositories_verified_count',
    'geo_status_failed_total': 'geo_status_failed_total',
    'geo_terraform_states': 'geo.terraform_states',
    'geo_terraform_states_checksum_failed': 'geo.terraform_states_checksum_failed',
    'geo_terraform_states_checksummed': 'geo.terraform_states_checksummed',
    'geo_terraform_states_failed': 'geo.terraform_states_failed',
    'geo_terraform_states_registry': 'geo.terraform_states_registry',
    'geo_terraform_states_synced': 'geo.terraform_states_synced',
    'geo_wikis_checksum_failed': 'geo.wikis_checksum_failed_count',
    'geo_wikis_checksum_failed_count': 'geo.wikis_checksum_failed_count',
    'geo_wikis_checksum_mismatch': 'geo.wikis_checksum_mismatch_count',
    'geo_wikis_checksum_mismatch_count': 'geo.wikis_checksum_mismatch_count',
    'geo_wikis_checksummed': 'geo.wikis_checksummed_count',
    'geo_wikis_checksummed_count': 'geo.wikis_checksummed_count',
    'geo_wikis_retrying_verification': 'geo.wikis_retrying_verification_count',
    'geo_wikis_retrying_verification_count': 'geo.wikis_retrying_verification_count',
    'geo_wikis_verification_failed': 'geo.wikis_verification_failed_count',
    'geo_wikis_verification_failed_count': 'geo.wikis_verification_failed_count',
    'geo_wikis_verified': 'geo.wikis_verified_count',
    'geo_wikis_verified_count': 'geo.wikis_verified_count',
    'gitlab_banzai_cached_render_real_duration_seconds': 'banzai.cached_render_real_duration_seconds',
    'gitlab_banzai_cacheless_render_real_duration_seconds': 'banzai.cacheless_render_real_duration_seconds',
    'gitlab_cache_misses_total': 'cache.misses_total',
    'gitlab_cache_operation_duration_seconds': 'cache.operation_duration_seconds',
    'gitlab_cache_operations_total': 'cache_operations_total',
    'gitlab_ci_pipeline_creation_duration_seconds': 'ci_pipeline_creation_duration_seconds',
    'gitlab_ci_pipeline_size_builds': 'ci_pipeline_size_builds',
    'gitlab_database_connection_pool_busy': 'database.connection_pool_busy',
    'gitlab_database_connection_pool_connections': 'database.connection_pool_connections',
    'gitlab_database_connection_pool_dead': 'database.connection_pool_dead',
    'gitlab_database_connection_pool_idle': 'database.connection_pool_idle',
    'gitlab_database_connection_pool_size': 'database.connection_pool_size',
    'gitlab_database_connection_pool_waiting': 'database.connection_pool_waiting',
    'gitlab_database_transaction_seconds': 'database.transaction_seconds',
    'gitlab_method_call_duration_seconds': 'method_call_duration_seconds',
    'gitlab_page_out_of_bounds': 'page_out_of_bounds',
    'gitlab_rails_queue_duration_seconds': 'rails_queue_duration_seconds',
    'gitlab_redis_client_exceptions_total': 'redis.client_exceptions_total',
    'gitlab_redis_client_requests_duration_seconds': 'redis.client_requests_duration_seconds',
    'gitlab_redis_client_requests_total': 'redis.client_requests_total',
    'gitlab_ruby_threads_max_expected_threads': 'ruby.threads_max_expected_threads',
    'gitlab_ruby_threads_running_threads': 'ruby.threads_running_threads',
    'gitlab_sql_duration_seconds': 'sql_duration_seconds',
    'gitlab_transaction_allocated_memory_bytes': 'transaction.allocated_memory_bytes',
    'gitlab_transaction_cache_count_total': 'transaction.cache_count_total',
    'gitlab_transaction_cache_duration_total': 'transaction.cache_duration_total',
    'gitlab_transaction_cache_read_hit_count_total': 'transaction.cache_read_hit_count_total',
    'gitlab_transaction_cache_read_miss_count_total': 'transaction.cache_read_miss_count_total',
    'gitlab_transaction_duration_seconds': 'transaction.duration_seconds',
    'gitlab_transaction_event_build_found_total': 'transaction.event_build_found_total',
    'gitlab_transaction_event_build_invalid_total': 'transaction.event_build_invalid_total',
    'gitlab_transaction_event_build_not_found_cached_total': 'transaction.event_build_not_found_cached_total',
    'gitlab_transaction_event_build_not_found_total': 'transaction.event_build_not_found_total',
    'gitlab_transaction_event_change_default_branch_total': 'transaction.event_change_default_branch_total',
    'gitlab_transaction_event_create_repository_total': 'transaction.event_create_repository_total',
    'gitlab_transaction_event_etag_caching_cache_hit_total': 'transaction.event_etag_caching_cache_hit_total',
    'gitlab_transaction_event_etag_caching_header_missing_total': 'transaction.event_etag_caching_header_missing_total',
    'gitlab_transaction_event_etag_caching_key_not_found_total': 'transaction.event_etag_caching_key_not_found_total',
    'gitlab_transaction_event_etag_caching_middleware_used_total': 'transaction.event_etag_caching_middleware_used_total',  # noqa
    'gitlab_transaction_event_etag_caching_resource_changed_total': 'transaction.event_etag_caching_resource_changed_total',  # noqa
    'gitlab_transaction_event_fork_repository_total': 'transaction.event_fork_repository_total',
    'gitlab_transaction_event_import_repository_total': 'transaction.event_import_repository_total',
    'gitlab_transaction_event_push_branch_total': 'transaction.event_push_branch_total',
    'gitlab_transaction_event_push_commit_total': 'transaction.event_push_commit_total',
    'gitlab_transaction_event_push_tag_total': 'transaction.event_push_tag_total',
    'gitlab_transaction_event_rails_exception_total': 'transaction.event_rails_exception_total',
    'gitlab_transaction_event_receive_email_total': 'transaction.event_receive_email_total',
    'gitlab_transaction_event_remote_mirrors_failed_total': 'transaction.event_remote_mirrors_failed_total',
    'gitlab_transaction_event_remote_mirrors_finished_total': 'transaction.event_remote_mirrors_finished_total',
    'gitlab_transaction_event_remote_mirrors_running_total': 'transaction.event_remote_mirrors_running_total',
    'gitlab_transaction_event_remove_branch_total': 'transaction.event_remove_branch_total',
    'gitlab_transaction_event_remove_repository_total': 'transaction.event_remove_repository_total',
    'gitlab_transaction_event_remove_tag_total': 'transaction.event_remove_tag_total',
    'gitlab_transaction_event_sidekiq_exception_total': 'transaction.event_sidekiq_exception_total',
    'gitlab_transaction_event_stuck_import_jobs_total': 'transaction.event_stuck_import_jobs_total',
    'gitlab_transaction_event_update_build_total': 'transaction.event_update_build_total',
    'gitlab_transaction_new_redis_connections_total': 'transaction.new_redis_connections_total',
    'gitlab_transaction_queue_duration_total': 'transaction.queue_duration_total',
    'gitlab_transaction_rails_queue_duration_total': 'transaction.rails_queue_duration_total',
    'gitlab_transaction_view_duration_total': 'transaction.view_duration_total',
    'gitlab_view_rendering_duration_seconds': 'view_rendering_duration_seconds',
    'global_search_awaiting_indexing_queue_size': 'global_search_awaiting_indexing_queue_size',
    'global_search_bulk_cron_queue_size': 'global_search_bulk_cron_queue_size',
    'http_elasticsearch_requests_duration_seconds': 'http.elasticsearch_requests_duration_seconds',
    'http_elasticsearch_requests_total': 'http.elasticsearch_requests_total',
    'http_request_duration_seconds': 'rack.http_request_duration_seconds',
    'http_requests_total': 'rack.http_requests_total',
    'job_waiter_started_total': 'job.waiter_started_total',
    'job_waiter_timeouts_total': 'job.waiter_timeouts_total',
    'pipelines_created_total': 'pipelines_created_total',
    'puma_active_connections': 'puma.active_connections',
    'puma_idle_threads': 'puma.idle_threads',
    'puma_killer_terminations_total': 'puma.killer_terminations_total',
    'puma_max_threads': 'puma.max_threads',
    'puma_pool_capacity': 'puma.pool_capacity',
    'puma_queued_connections': 'puma.queued_connections',
    'puma_running': 'puma.running',
    'puma_running_workers': 'puma.running_workers',
    'puma_stale_workers': 'puma.stale_workers',
    'puma_workers': 'puma.workers',
    'rack_uncaught_errors_total': 'rack.uncaught_errors_total',
    'ruby_file_descriptors': 'ruby.file_descriptors',
    'ruby_gc_duration_seconds': 'ruby.gc_duration_seconds',
    'ruby_gc_stat_count': 'ruby.gc_stat.count',
    'ruby_gc_stat_heap_allocatable_pages': 'ruby.gc_stat.heap_allocatable_pages',
    'ruby_gc_stat_heap_allocated_pages': 'ruby.gc_stat.heap_allocated_pages',
    'ruby_gc_stat_heap_available_slots': 'ruby.gc_stat.heap_available_slots',
    'ruby_gc_stat_heap_eden_pages': 'ruby.gc_stat.heap_eden_pages',
    'ruby_gc_stat_heap_final_slots': 'ruby.gc_stat.heap_final_slots',
    'ruby_gc_stat_heap_free_slots': 'ruby.gc_stat.heap_free_slots',
    'ruby_gc_stat_heap_live_slots': 'ruby.gc_stat.heap_live_slots',
    'ruby_gc_stat_heap_marked_slots': 'ruby.gc_stat.heap_marked_slots',
    'ruby_gc_stat_heap_sorted_length': 'ruby.gc_stat.heap_sorted_length',
    'ruby_gc_stat_heap_tomb_pages': 'ruby.gc_stat.heap_tomb_pages',
    'ruby_gc_stat_major_gc_count': 'ruby.gc_stat.major_gc_count',
    'ruby_gc_stat_malloc_increase_bytes': 'ruby.gc_stat.malloc_increase_bytes',
    'ruby_gc_stat_malloc_increase_bytes_limit': 'ruby.gc_stat.malloc_increase_bytes_limit',
    'ruby_gc_stat_minor_gc_count': 'ruby.gc_stat.minor_gc_count',
    'ruby_gc_stat_old_objects': 'ruby.gc_stat.old_objects',
    'ruby_gc_stat_old_objects_limit': 'ruby.gc_stat.old_objects_limit',
    'ruby_gc_stat_oldmalloc_increase_bytes': 'ruby.gc_stat.oldmalloc_increase_bytes',
    'ruby_gc_stat_oldmalloc_increase_bytes_limit': 'ruby.gc_stat.oldmalloc_increase_bytes_limit',
    'ruby_gc_stat_remembered_wb_unprotected_objects': 'ruby.gc_stat.remembered_wb_unprotected_objects',
    'ruby_gc_stat_remembered_wb_unprotected_objects_limit': 'ruby.gc_stat.remembered_wb_unprotected_objects_limit',
    'ruby_gc_stat_total_allocated_objects': 'ruby.gc_stat.total_allocated_objects',
    'ruby_gc_stat_total_allocated_pages': 'ruby.gc_stat.total_allocated_pages',
    'ruby_gc_stat_total_freed_objects': 'ruby.gc_stat.total_freed_objects',
    'ruby_gc_stat_total_freed_pages': 'ruby.gc_stat.total_freed_pages',
    'ruby_memory_bytes': 'ruby.memory_bytes',
    'ruby_process_cpu_seconds_total': 'ruby.process_cpu_seconds_total',
    'ruby_process_max_fds': 'ruby.process_max_fds',
    'ruby_process_proportional_memory_bytes': 'ruby.process_proportional_memory_bytes',
    'ruby_process_resident_memory_bytes': 'ruby.process_resident_memory_bytes',
    'ruby_process_start_time_seconds': 'ruby.process_start_time_seconds',
    'ruby_process_unique_memory_bytes': 'ruby.process_unique_memory_bytes',
    'ruby_sampler_duration_seconds': 'ruby.sampler_duration_seconds',
    'ruby_sampler_duration_seconds_total': 'ruby.sampler_duration_seconds_total',
    'sidekiq_concurrency': 'sidekiq.concurrency',
    'sidekiq_elasticsearch_requests_duration_seconds': 'sidekiq.elasticsearch_requests_duration_seconds',
    'sidekiq_elasticsearch_requests_total': 'sidekiq.elasticsearch_requests_total',
    'sidekiq_jobs_completion_seconds': 'sidekiq.jobs_completion_seconds',
    'sidekiq_jobs_cpu_seconds': 'sidekiq.jobs_cpu_seconds',
    'sidekiq_jobs_db_seconds': 'sidekiq.jobs_db_seconds',
    'sidekiq_jobs_failed_total': 'sidekiq.jobs_failed_total',
    'sidekiq_jobs_gitaly_seconds': 'sidekiq.jobs_gitaly_seconds',
    'sidekiq_jobs_queue_duration_seconds': 'sidekiq.jobs_queue_duration_seconds',
    'sidekiq_jobs_retried_total': 'sidekiq.jobs_retried_total',
    'sidekiq_redis_requests_duration_seconds': 'sidekiq.redis_requests_duration_seconds',
    'sidekiq_redis_requests_total': 'sidekiq.redis_requests_total',
    'sidekiq_running_jobs': 'sidekiq.running_jobs',
    'successful_login_captcha_total': 'successful_login_captcha_total',
    'unicorn_active_connections': 'unicorn.active_connections',
    'unicorn_queued_connections': 'unicorn.queued_connections',
    'unicorn_workers': 'unicorn.workers',
    'upload_file_does_not_exist': 'upload_file_does_not_exist',
    'user_session_logins_total': 'user_session_logins_total',
}

OPENMETRICS_V2_TYPE_OVERRIDES = {
    "gitlab_transaction_rails_queue_duration_total": "gauge",
    "ruby_process_cpu_seconds_total": "gauge",
    "geo_group_wiki_repositories_checksum_total": "gauge",
    "geo_group_wiki_repositories_verification_total": "gauge",
    "geo_project_repositories_checksum_total": "gauge",
    "geo_project_repositories_verification_total": "gauge",
    "geo_project_wiki_repositories_checksum_total": "gauge",
    "geo_project_wiki_repositories_verification_total": "gauge",
}


GITALY_METRICS_MAP = {
    "gitaly_cacheinvalidator_rpc": "cacheinvalidator_rpc",
    "gitaly_catfile_cache_members": "catfile_cache_members",
    "gitaly_catfile_processes": "catfile_processes",
    "gitaly_command_context_switches": "command.context_switches",
    "gitaly_command_cpu_seconds": "command.cpu_seconds",
    "gitaly_command_major_page_faults": "command.major_page_faults",
    "gitaly_command_minor_page_faults": "command.minor_page_faults",
    "gitaly_command_real_seconds": "command.real_seconds",
    "gitaly_command_signals_received": "command.signals_received",
    "gitaly_command_spawn_token_acquiring_seconds": "command.spawn_token_acquiring_seconds",
    "gitaly_commands_running": "commands_running",
    "gitaly_concurrency_limiting_acquiring_seconds": "concurrency_limiting_acquiring_seconds",
    "gitaly_concurrency_limiting_in_progress": "concurrency_limiting_in_progress",
    "gitaly_concurrency_limiting_queued": "concurrency_limiting_queued",
    "gitaly_diskcache_bytes_fetched": "diskcache.bytes_fetched",
    "gitaly_diskcache_bytes_loser": "diskcache.bytes_loser",
    "gitaly_diskcache_bytes_stored": "diskcache.bytes_stored",
    "gitaly_diskcache_miss": "diskcache.miss",
    "gitaly_diskcache_requests": "diskcache.requests",
    "gitaly_diskcache_walker_empty_dir_removal": "diskcache.walker_empty_dir_removal",
    "gitaly_diskcache_walker_empty_dir": "diskcache.walker_empty_dir",
    "gitaly_diskcache_walker_error": "diskcache.walker_error",
    "gitaly_diskcache_walker_removal": "diskcache.walker_removal",
    "gitaly_hook_transaction_voting_delay_seconds": "hook_transaction_voting_delay_seconds",
    "gitaly_inforef_cache_attempt": "inforef_cache_attempt",
    "gitaly_list_commits_by_oid_request_size": "list_commits_by_oid_request_size",
    "gitaly_pack_objects_acquiring_seconds": "pack_objects.acquiring_seconds",
    "gitaly_pack_objects_generated_bytes": "pack_objects.generated_bytes",
    "gitaly_pack_objects_in_progress": "pack_objects.in_progress",
    "gitaly_pack_objects_queued": "pack_objects.queued",
    "gitaly_pack_objects_served_bytes": "pack_objects.served_bytes",
    "gitaly_spawn_timeouts": "spawn_timeouts",
    "gitaly_streamcache_sendfile_bytes": "streamcache_sendfile_bytes",
    "go_gc_duration_seconds": "go.gc_duration_seconds",
    "go_goroutines": "go.goroutines",
    "go_info": "go.info",
    "go_memstats_alloc_bytes": "go.memstats_alloc_bytes",
    "go_memstats_buck_hash_sys_bytes": "go.memstats_buck_hash_sys_bytes",
    "go_memstats_frees": "go.memstats_frees",
    "go_memstats_gc_sys_bytes": "go.memstats_gc_sys_bytes",
    "go_memstats_heap_alloc_bytes": "go.memstats_heap_alloc_bytes",
    "go_memstats_heap_idle_bytes": "go.memstats_heap_idle_bytes",
    "go_memstats_heap_inuse_bytes": "go.memstats_heap_inuse_bytes",
    "go_memstats_heap_objects": "go.memstats_heap_objects",
    "go_memstats_heap_released_bytes": "go.memstats_heap_released_bytes",
    "go_memstats_heap_sys_bytes": "go.memstats_heap_sys_bytes",
    "go_memstats_last_gc_time_seconds": "go.memstats_last_gc_time_seconds",
    "go_memstats_lookups": "go.memstats_lookups",
    "go_memstats_mallocs": "go.memstats_mallocs",
    "go_memstats_mcache_inuse_bytes": "go.memstats_mcache_inuse_bytes",
    "go_memstats_mcache_sys_bytes": "go.memstats_mcache_sys_bytes",
    "go_memstats_mspan_inuse_bytes": "go.memstats_mspan_inuse_bytes",
    "go_memstats_mspan_sys_bytes": "go.memstats_mspan_sys_bytes",
    "go_memstats_next_gc_bytes": "go.memstats_next_gc_bytes",
    "go_memstats_other_sys_bytes": "go.memstats_other_sys_bytes",
    "go_memstats_stack_inuse_bytes": "go.memstats_stack_inuse_bytes",
    "go_memstats_stack_sys_bytes": "go.memstats_stack_sys_bytes",
    "go_memstats_sys_bytes": "go.memstats_sys_bytes",
    "go_threads": "go.threads",
    "grpc_server_handled": "grpc_server.handled",
    "grpc_server_handling_seconds": "grpc_server.handling_seconds",
    "grpc_server_msg_received": "grpc_server.msg_received",
    "grpc_server_msg_sent": "grpc_server.msg_sent",
    "grpc_server_started": "grpc_server.started",
    "process_cpu_seconds": "process_cpu_seconds",
    "process_max_fds": "process_max_fds",
    "process_open_fds": "process_open_fds",
    "process_resident_memory_bytes": "process_resident_memory_bytes",
    "process_start_time_seconds": "process_start_time_seconds",
    "process_virtual_memory_bytes": "process_virtual_memory_bytes",
    "process_virtual_memory_max_bytes": "process_virtual_memory_max_bytes",
    "promhttp_metric_handler_requests_in_flight": "promhttp_metric_handler_requests_in_flight",
    "promhttp_metric_handler_requests": "promhttp_metric_handler_requests",
}


def construct_metrics_config(metric_map):
    metrics = []
    for raw_metric_name, metric_name in metric_map.items():
        if raw_metric_name not in OPENMETRICS_V2_TYPE_OVERRIDES:
            if raw_metric_name.endswith('_total'):
                raw_metric_name = raw_metric_name[:-6]
                metric_name = metric_name[:-6]

            elif metric_name.endswith('.count'):
                metric_name = metric_name[:-6]

            config = {raw_metric_name: {'name': metric_name}}
        else:
            config = {raw_metric_name: {'name': metric_name, 'type': OPENMETRICS_V2_TYPE_OVERRIDES[raw_metric_name]}}

        metrics.append(config)

    return metrics
